﻿Imports CRM.BusinessLayer
Partial Public Class frmAddEmail
    Private _EmailId As Long
    Public OldEmailTitle As String
    Public OldEmailAddress As String
    Public _cboDesc As String

    Public Property EMailId() As Long
        Get
            Return _EmailId
        End Get
        Set(ByVal value As Long)
            _EmailId = value
        End Set
    End Property
    Public Property cboDesc() As String
        Get
            Return _cboDesc
        End Get
        Set(ByVal value As String)
            _cboDesc = value
        End Set
    End Property
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSave.Click
        Dim Msg As String
        Try
            If Me.cboDescription.Text.Trim = String.Empty Then
                CommonFuncs.DisplayMessage("You must enter a title for this email address!", CommonDialog.CustomDialogIcons.Information, "Error")
                Me.cboDescription.Focus()
                Exit Sub
            End If

            If Me.txtEmailAddress.Text.Trim = String.Empty Then
                CommonFuncs.DisplayMessage("You must enter an email address!", CommonDialog.CustomDialogIcons.Information, "Error")
                Me.txtEmailAddress.Focus()
                Exit Sub
            End If

            Msg = CommonFuncs.Gblfunc_Validate_EmailAddress(Me.txtEmailAddress.Text.Trim)

            If Msg <> "" Then
                CommonFuncs.DisplayMessage(Msg, CommonDialog.CustomDialogIcons.Information, String.Empty)
                Me.txtEmailAddress.Focus()
                Exit Sub
            End If

            If People.AddEmailAddress(Me.cboDescription.Text, Me.txtEmailAddress.Text, GlobalCRM.CurrentCandidateID, False, GlobalCRM.CurrentConName, EMailId, OldEmailTitle, OldEmailAddress) > 0 Then
                Me.Close()
            End If
        Catch ex As Exception
            Dim incidentno As Long
            incidentno = CommonFuncs.ErrorHandler(ex, "frmAddEmail : btnsave_click")
            'If incidentno > 0 Then
            '    MsgBox("The incident has been created and sent to IT." & vbCrLf & vbCrLf & "Please quote the incident number : " & incidentno & " to It for future correspondences", MsgBoxStyle.Information, "IT")
            'Else
            '    MsgBox("Please contact IT directly. The message was not created.", MsgBoxStyle.Critical, "IT")
            'End If
        End Try
    End Sub

    Private Sub frmAddEmail_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Me.KeyUp
        If e.Key = Key.Escape Then
            Me.Close()
        End If
    End Sub

    Private Sub frmAddEmail_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        GeneralTasks.ChangeTheme(Me)
        GeneralTasks.EnumerateandFill(Me.LogicalChildren)
        Me.OldEmailTitle = Me.cboDescription.Text
        Me.OldEmailAddress = Me.txtEmailAddress.Text
        If cboDesc <> "Main" Then
            If cboDesc <> "Secondary" Then
                Me.cboDescription.Text = "Secondary"
            Else
                Me.cboDescription.Text = "Secondary"
            End If
        Else
            Me.cboDescription.Text = "Main"
        End If
    End Sub
End Class
